/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.usc.csci538.hw6;

import java.util.Calendar;

/**
 *
 * @author yaoli
 */
public class Utils {
    public static String timeAsString(int hour, int min, boolean isAM) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(hour);
        buffer.append(":");
        if (min < 10) {
            buffer.append(0);
        }
        buffer.append(min);
        if (isAM) {
            buffer.append("AM");
        } else {
            buffer.append("PM");
        }
        return buffer.toString();
    }
    
    public static String monthAsString(int month) {
        switch (month) {
            case Calendar.JANUARY: return "January";
            case Calendar.FEBRUARY: return "February";
            case Calendar.MARCH: return "March";
            case Calendar.APRIL: return "April";
            case Calendar.MAY: return "May";
            case Calendar.JUNE: return "June";
            case Calendar.JULY: return "July";
            case Calendar.AUGUST: return "August";
            case Calendar.SEPTEMBER: return "September";
            case Calendar.OCTOBER: return "October";
            case Calendar.NOVEMBER: return "November";
            case Calendar.DECEMBER: return "December";
        }
        throw new RuntimeException("Invalid date");
    }
    
    public static String dayOfWeekAsString(int dayOfWeek) {
        switch (dayOfWeek) {
            case Calendar.MONDAY: return "Mon";
            case Calendar.TUESDAY: return "Tue";
            case Calendar.WEDNESDAY: return "Wed";
            case Calendar.THURSDAY: return "Thurs";
            case Calendar.FRIDAY: return "Fri";
            case Calendar.SATURDAY: return "Sat";
            case Calendar.SUNDAY: return "Sun";
        }
        throw new RuntimeException("Invalid date");
    }
    public static String numDayOfWeekAsString(int dayOfWeek) {
        switch (dayOfWeek) {
            case 1: return "Mon";
            case 2: return "Tue";
            case 3: return "Wed";
            case 4: return "Thurs";
            case 5: return "Fri";
            case 6: return "Sat";
            case 0: return "Sun";
        }
        throw new RuntimeException("Invalid date");
    }
    public static String dateAsString(int year, int month, int date) {
        StringBuffer buffer = new StringBuffer();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        cal.set(Calendar.DATE, date);
        
        buffer.append(dayOfWeekAsString(cal.get(Calendar.DAY_OF_WEEK)));
        buffer.append(" ");
        buffer.append(monthAsString(month));
        buffer.append(" ");
        buffer.append(date);
        buffer.append(", ");
        buffer.append(year);
        return buffer.toString();
    }
    
    public static int timeAsInteger(int hour, int minute, boolean isAM) {
        return hour * 100 + minute + (isAM ? 0 : 1000);
    }
}
